package be.kuleuven.cs.mop.app.controllers;


import be.kuleuven.cs.mop.app.System;
import be.kuleuven.cs.mop.domain.exceptions.InvalidCurrentUserException;
import be.kuleuven.cs.mop.domain.model.impl.UserImpl;
import be.kuleuven.cs.mop.domain.model.impl.World;



/**
 * Class providing standard <code>Controller</code> functionality
 */
public abstract class Controller {
	
	/**
	 * The system
	 */
	private final System system;
	
	
	protected Controller(final System system) {
		if (system == null)
			throw new NullPointerException("System == NULL");
		this.system = system;
	}
	
	
	
	
	/**
	 * Returns the {@link World} for this <code>Controller</code>
	 */
	protected World getWorld() { return getSystem().getWorld(); }
	
	/**
	 * Returns the {@link System} for this <code>Controller</code>
	 */
	protected System getSystem() { return system; }
	
	/*
	 * Returns the current user in the system
	 * 
	 * @throws TaskManagerException NO_USER_LOGGED_IN - No current user
	 */
	protected UserImpl getCurrentUser() throws InvalidCurrentUserException { 
		return getSystem().getCurrentUser(); 
	}
	
	/**
	 * @see System#checkIfCurrentUserIsAdmin()
	 */
	public void checkIfCurrentUserIsAdmin() throws InvalidCurrentUserException {
		getSystem().checkIfCurrentUserIsAdmin();
	}
	
	/**
	 * @see System#checkIfUserIsLoggedIn()
	 */
	public void checkIfUserIsLoggedIn() throws InvalidCurrentUserException {
		getSystem().checkIfUserIsLoggedIn();
	}
}